package com.demo.servlet.demo1220;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/demo1220/demo01.do")
public class Demo01Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取 Session 方法
        HttpSession session = request.getSession();
        String id = session.getId();
        boolean flag = session.isNew();
        //设置 Session 生命周期
//        session.setMaxInactiveInterval(5);
        System.out.println(id);
        System.out.println(flag);
        //获取 Session 生命周期
        System.out.println(session.getMaxInactiveInterval());
        //让 Session 立刻销毁
        session.invalidate();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
